package com.aiobc.community.common.business.controller;

import com.aiobc.community.common.business.enums.SystemUserLevelEnum;
import org.springframework.web.bind.annotation.RequestMapping;
import com.aiobc.community.common.business.service.DeviceInfoService;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.*;
import springfox.documentation.annotations.ApiIgnore;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.aiobc.community.common.business.vo.resp.DeviceInfoVO;
import com.aiobc.community.common.business.vo.req.DeviceInfoQryReq;
import com.aiobc.community.common.business.vo.req.DeviceInfoAddReq;
import com.aiobc.community.common.business.vo.req.DeviceInfoUpdateReq;
import lombok.AllArgsConstructor;

import java.util.List;

/**
 * 设备基本信息 前端控制器
 * @author zhangzl
 * @since 2021-01-20
 */
@Api(tags = {"设备基本信息-管理"})
@RestController
@RequestMapping("/deviceInfo")
@AllArgsConstructor
public class DeviceInfoController {

    private final DeviceInfoService deviceInfoService;

    @GetMapping("getEnums")
    @ApiOperation(value = "用户级别-枚举", notes = "用户级别-枚举")
    public R<SystemUserLevelEnum[]> getEnums(){
        return R.ok(SystemUserLevelEnum.values());
    }

    /**
     * 设备基本信息查询-分页
     */
    @GetMapping("page")
    @ApiOperation(value = "设备基本信息查询-分页", notes = "设备基本信息查询-分页")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "current", value = "当前的页数", defaultValue = "1"),
        @ApiImplicitParam(name = "size", value = "当前分页的条数", defaultValue = "10")
    })
    public R<Page<DeviceInfoVO>> page(@ApiIgnore Page page,DeviceInfoQryReq req) {
      return R.ok(deviceInfoService.pageExt(page,req));
    }

    /**
     * 设备基本信息查询-非分页
     */
    @GetMapping("")
    @ApiOperation(value = "设备基本信息查询-非分页", notes = "设备基本信息查询-非分页")
    public R<List<DeviceInfoVO>> list(DeviceInfoQryReq req) {
      return R.ok(deviceInfoService.listExt(req));
    }

    /**
     * 通过id查询设备基本信息
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "通过id查询设备基本信息", notes = "通过id查询设备基本信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "主键id", required = true)
    })
    public R<DeviceInfoVO> getById(@PathVariable("id") String id){
        return R.ok(deviceInfoService.getByIdExt(id));
    }

    /**
     * 新增设备基本信息
     */
    @PostMapping
    @ApiOperation(value = "新增设备基本信息", notes = "新增设备基本信息")
    public R<Boolean> save(@RequestBody DeviceInfoAddReq req){
        return R.ok(deviceInfoService.saveExt(req));
    }

    /**
     * 修改设备基本信息
     */
    @PutMapping("")
    @ApiOperation(value = "修改设备基本信息", notes = "修改设备基本信息")
    public R<Boolean> updateById(@RequestBody DeviceInfoUpdateReq req){
        return R.ok(deviceInfoService.updateByIdExt(req));
    }

    /**
     * 通过id删除设备基本信息
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除设备基本信息", notes = "删除设备基本信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "主键id", required = true)
    })
    public R<Boolean> delete(@PathVariable String id){
        return R.ok(deviceInfoService.removeById(id));
    }
}

